package com.hyacinth.server.util;

import com.sun.istack.internal.Nullable;
import org.apache.logging.log4j.core.util.ArrayUtils;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
 * 集合工具类
 * @author zhangfb
 * @version 1.0.0.1
 * @since JDK 1.8
 */
public class CollectionUtils {

    public static boolean isEmpty(Collection<?> collection) {
        return (collection == null || collection.isEmpty());
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return (map == null || map.isEmpty());
    }

    public static boolean isEmpty(Object ... objects) {
        return (objects == null || objects.length ==0);
    }

    public static boolean isEmpty(Class<?> ... classes) {
        return (classes == null || classes.length ==0);
    }

    public static boolean contains(Iterator<?> iterator, Object element) {
        if (iterator != null) {
            while (iterator.hasNext()) {
                Object candidate = iterator.next();
                if (ObjectUtils.nullSafeEquals(candidate, element)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean contains(Object[] objects, Object element) {
        if (!isEmpty(objects)) {
            for (Object object : objects) {
                if (ObjectUtils.nullSafeEquals(object, element)) {
                    return true;
                }
            }
        }
        return false;
    }
}
